<#import "/spring.ftl" as spring>

<#macro header title>
<html>
<head>
  	<meta http-equiv="content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="content-language" content="pl">
	<title><@spring.message "app.title" /> - <@spring.message "${title}" /></title>
	<link rel="stylesheet" type="text/css" href="static/css/default.css" />
	<link rel="stylesheet" type="text/css" href="static/css/smoothness/jquery-ui-1.8.7.custom.css" />
	<script type="text/javascript" src="static/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="static/js/jquery-ui-1.8.7.custom.min.js"></script>
	<script type="text/javascript" src="static/js/combobox.js"></script>
	<#nested>
</head>
</#macro>

<#macro body hideOptions="false">
<body>
<div class="container">
	<div class="main">
		<div class="header">
			<div class="title"><h1><@spring.message "app.title" /></h1></div>
		</div>
		
		<div class="content" <#if hideOptions == "true"> style="float: none; margin: auto;" </#if>>
			<div class="item">
				<#nested>
			</div>
		</div>
		<#if hideOptions != "true">
			<div class="sidenav">
				<h1>Menu</h1>
				<ul>
					<#if (cmd.isUser)?? && !cmd.isUser>
					<li><a href="my_dead.htm"><@spring.message "sidenav.my_dead" /></a></li>
					<li><a href="my_payments.htm"><@spring.message "sidenav.my_payments" /></a></li>
					<li><a href="my_quaters.htm"><@spring.message "sidenav.my_quaters" /></a></li>
					</#if>
					<li><a href="my_account.htm"><@spring.message "sidenav.my_account" /></a></li>
					<li><a href="<@spring.url "/j_spring_security_logout"/>"><@spring.message "sidenav.logout" /></a></li>
				</ul>
			</div>
		</#if>
		<div class="clearer"><span></span></div>
	</div>
		
	<div class="footer">
		<span class="right"><p><@spring.message "footer.author" /></p></span>
		<div class="clearer"><span></span></div>
	</div>
</div>
</body>
</html>
</#macro>

<#macro section title description="">
<div class="item">
	<#if title != "">
		<h1><@spring.message "${title}" /></h1>
	</#if>
	<#if description != "">
		<div class="descr"><@spring.message "${description}" /></div>
	</#if>
	<#nested>
</div>
</#macro>

<#macro label field value width="40%" resource=true>
	<label for=${field} class="label" style="width: ${width}"> 
		<#if resource>
			<@spring.message "${value}"/>
		<#else>
			${value}
		</#if>
	</label>
</#macro>

<#macro errorsFrame>
<div id="errorsFrame" class="ui-widget">
	<div id="errorText" class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em; margin-bottom:5px;">
        <p style="padding-bottom:0;">
        	<span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>
        	<strong><@spring.message "error.alert" /></strong>
        </p>
    </div>
    <script type="text/javascript">
        	$(function() {
        		$("#errorsFrame").hide();
        	});
    </script>
</div>
</#macro>

<#macro button name value style="">
	<input type="submit" id=${name} name=${name} value=<@spring.message "${value}" /> <#if style != "">style="${style}"</#if> />
	<script>
	$(function() {
		$( "#${name}").button();
	});
	</script>
</#macro>

<#macro input field label type="text" other="">
<@l.label field="${field}" value="${label}"/>
<@spring.bind "${field}"/>
<input id="${field}" type="${type}" name="${spring.status.expression}" value="${spring.status.value?default("")}" ${other} />
<#if spring.status.error>
     <#list spring.status.errorMessages as error>
     	<script type="text/javascript">
        	$(function() {
        		$("#errorText").append('<p style="padding-bottom:0;">${error}</p>');
        		$("#errorsFrame").show();
        	});
        </script>
     </#list>   
</#if>
</#macro>

<#macro textarea field label title="" other="">
<@l.label field="${field}" value="${label}" resource=false />
<@spring.bind "${field}"/>
<textarea id="${field}" name="${spring.status.expression}" title="${title}" ${other}>${spring.status.value?default("")}
</textarea>
<#if spring.status.error>
     <#list spring.status.errorMessages as error>
     	<script type="text/javascript">
        	$(function() {
        		$("#errorText").append('<p style="padding-bottom:0;">${error}</p>');
        		$("#errorsFrame").show();
        	});
        </script>
     </#list>   
</#if>
</#macro>

<#macro combobox field label options title="" other="" resourceMsgs=false>
<@l.label field="${field}" value="${label}" resource=resourceMsgs/>
<@spring.bind "${field}"/>
<select id="${field}" name="${spring.status.expression}" title="${title}" ${other}>
    <#list options as value>
    	<option value="${value.value}" <@spring.checkSelected value.value/> title="${value.title}">${value.name}</option>
    </#list>
</select>
<script type="text/javascript">	
	$(function() {
		$( "#${escape(field)}" ).combobox();
	});
</script>
<#if spring.status.error>
     <#list spring.status.errorMessages as error>
     	<script type="text/javascript">
        	$(function() {
        		$("#errorText").append('<p style="padding-bottom:0;">${error}</p>');
        		$("#errorsFrame").show();
        	});
        </script>
     </#list>   
</#if>
</#macro>

<#macro checkbox field label title="" other="">
	<@spring.bind "${field}"/>
	<#assign isSelected = spring.contains(spring.status.value?default([""]), "true")>
	<input type="checkbox" id="${field}" name="${spring.status.expression}" value="true"<#if isSelected> checked="checked"</#if> title="${title}" ${other}<@spring.closeTag/>
	<@l.label field="${field}" value="${label}" resource=false/>
</#macro>

<#function escape str>
	<#return str?replace('.','\\\\.') />
</#function>
